// import { getLoginUserAndUserDept } from '@/api/sidebar'
export default {
  namespaced: true,
  state: {
    user: {
      loginuser: '',
      userDept: '',
      userId: ''
    },
    aircraftModels: [],
    aircraftModel: sessionStorage.getItem('aircraftModel') || '',
    rolesName: [],
    roleName: sessionStorage.getItem('roleName') || ''
  },
  getters: {

  },
  mutations: {
    setTest (state, payload) {
      state.test = payload
    },
    setUser (state, payload) {
      state.user = payload
    },
    setAircraftModels (state, payload) {
      state.aircraftModels = payload
    },
    setAircraftModel (state, payload) {
      state.aircraftModel = payload
      sessionStorage.setItem('aircraftModel', payload)
    },
    setRolesName (state, payload) {
      state.rolesName = payload
    },
    setRoleName (state, payload) {
      state.roleName = payload
      sessionStorage.setItem('roleName', payload)
    }
  },
  actions: {
    // 获取用户信息 TODO
    async  getUser ({
      commit
    }) {
      let res = {
        loginuser: 1,
        userDept: 1,
        uid: 1,
        aircraftModel: 'C919',
        pageSelect: '工程师'
      }
      // let res = await getLoginUserAndUserDept()
      let user = {}
      let aircraftModels = []
      let rolesName = []
      user.loginuser = res.loginuser
      user.userDept = res.userDept
      user.userId = res.uid
      aircraftModels = res.aircraftModel
      rolesName = res.pageSelect
      commit('setUser', user)
      commit('setAircraftModels', aircraftModels)
      commit('setRolesName', rolesName)
      commit('setRoleName', sessionStorage.getItem('roleName') || rolesName[0])
    }
  }
}
